/*
 *  This project is mainly focused on developing more and more utilisties
 *  like mail utilities, dao utilities, ldap utilities, file utilities, 
 *  file importing utilities etc. for easy coding in java.
 *  
 *  Copyright (C) 2012  R.Satheesh Kumar alias GURU
 *  
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *  
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *  
 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
package org.jsmart.util.list;

import java.util.List;
import org.jsmart.util.RowMapper;
import org.jsmart.util.core.Utils;
import org.jsmart.util.core.AbstractUtils;
import org.jsmart.util.core.AbstractItemCallback;
import org.jsmart.util.core.AbstractItemFilter;
import org.jsmart.util.core.UtilsException;

/**
 * This method is used to perform the utilities with List
 * @author R.Satheesh Kumar alias GURU {pulsarcoder@gmail.com}
 * @since v1.0
 * @see List
 * @see Utils
 */
public abstract class ListUtils extends AbstractUtils {
    public static <U> List<U> query(final List<U> list,
            final AbstractItemCallback<U, U> callback,
            final AbstractItemFilter<U> filter,
            Boolean singleData) throws UtilsException {
        return AbstractUtils.execute(list, new QueryListCaller<U>(callback, filter, singleData));
    }

    public static <U> List<U> query(final List<U> list,
            final AbstractItemCallback<U, U> callback) throws UtilsException {
        return query(list, callback, new AbstractUtils.SimpleAbstractItemFilter<U>(), false);
    }

    public static <U> List<U> query(final List<U> list,
            final RowMapper<U, U> rowMapper,
            final AbstractItemFilter<U> filter,
            Boolean singleData) throws UtilsException {
        return query(list, AbstractUtils.getSimpleItemCallback(rowMapper), filter, singleData);
    }

    public static <U> U queryForObject(final List<U> list,
            final RowMapper<U, U> rowMapper,
            final AbstractItemFilter<U> filter) throws UtilsException {
        return query(list, rowMapper, filter, true).get(0);
    }

    public static <U> U queryForObject(final List<U> list,
            final RowMapper<U, U> rowMapper) throws UtilsException {
        return queryForObject(list, rowMapper, new AbstractUtils.SimpleAbstractItemFilter<U>());
    }
}
